<? 
include "include/config.php";  
 $location='agenda';
 if(!isset($_SESSION['_user']))
{ 
header("location: login.php");
}

     
    $nume_site = addslashes($_POST['site_nume']);
    $adresa_site = addslashes($_POST['site_adresa']);
    $username = addslashes($_POST['username']);
    $parola = addslashes($_POST['site_parola']);
    $email = addslashes($_POST['email']);


if ($_GET['sterge'])
    mysql_query ("delete from agenda where id='" . $_GET['sterge'] . "'");

 
if ($_GET['modifica'])
    {
    $user_mod_query=mysql_query("select * from agenda where id='" . $_GET['modifica'] . "'");
    $data_mod=mysql_fetch_array($user_mod_query) ;
        
    } 
 if ($_POST['modifica_data'] != '')
    {
   
        
        
    $sql = "UPDATE agenda SET numesite='$nume_site',adresasite='$adresa_site',username='$username',parola='$parola',email='$email' WHERE id=".$_POST['modifica_data'] ;
    $result = mysql_query($sql) or die ('Probleme la update');
     $mesaj=  "Informatia s-a schimbat cu succes!";
    } 

    
 if (($_POST['adauga']!='')AND($_POST['modifica_data']=='' ) )
 {
    $insert =mysql_query("INSERT INTO agenda(numesite, adresasite, username, parola, email) VALUES('".$nume_site."', '".$adresa_site."','".$username."','".$parola."','".$email."')") or die ('Problema la salvare !!');
    $mesaj= "Date adaugate cu succes!";
} 

 $date_q=mysql_query('select * from agenda order by id');
 while ($date=mysql_fetch_array($date_q))
 $mesaje[]=$date;
 

 include "include/head.php"; 

?>


<div id="container">
<? include "include/meniu.php"; ?>

<div id="submenu"><div><div>
    <ul>
        <li id="off2"><a href="ag_view.php">Operatii</a></li>
    </ul>
</div></div></div>

<div class="clear"></div>
<div id="content"><div id="mid">
<div>

           <h2>Introduceti date: </h2>

            <form action = "ag_view.php" method = "post" enctype = "multipart/form-data"  >
            <input type='hidden' name='modifica_data'  value='<?=$_GET['modifica']?>' />
                 <label>Username</label>

                <input name = "username"  type = "text" class = "tf b" value='<?=stripslashes($data_mod['username'])?>'/>

                <br class = "clear"/>
                <label>Nume Site</label>

                <input name = "site_nume"  type = "text" class = "tf b" value='<?=stripslashes($data_mod['numesite'])?>'/>

                <br class = "clear"/>

                <label>Adresa Site</label>

                <input name = "site_adresa"  type = "text" class = "tf b" value='<?=stripslashes($data_mod['adresasite'])?>'/>

                <br class = "clear"/>

                <label>Parola</label>

                <input name = "site_parola"  type = "text" class = "tf b" value='<?=stripslashes($data_mod['parola'])?>'/>
                  <br class = "clear"/> 
                <label>Email</label>

                <input name = "email"  type = "text" class = "tf b" value='<?=stripslashes($data_mod['email'])?>'/>

                <br class = "clear"/>

                <br class = "clear"/>

                <label>&nbsp;</label>

                <input type = "submit" name = "adauga" value = "Adauga" class = "ok"/>
                <br class = "clear"/>
            </form>
            
            <? if ($mesaj!='') {?>
<br class="clear" />
<br class="clear" />
<div class="cell__ bbbbb ac"><strong><?=$mesaj?></strong></div> <br class="clear" /> 
<?}?>
                
             <h2>DATE AGENDA</h2>

            <div>
                <div class = "cell s">Nr</div>
                <div class = "cell bb">Username</div>
                <div class = "cell bb ">Nume Site</div>
                <div class = "cell bb ">Adresa site</div>
                <div class = "cell bb ">Parola</div>
                <div class = "cell bb ">Email</div> 
                <br class = "clear"/>

                <? $i=0; foreach ($mesaje as $mesaj) { 
                    if ($i%2==0 ) $class='cell__'; else $class='cell_' ;
                    ?>

                <div  class="<?=$class?> s"><strong><?=$mesaj['id']?></strong>&nbsp; </div>
                <div class="<?=$class?> bb"><?=$mesaj['username']?>&nbsp;</div>
                <div class="<?=$class?> bb"><?=$mesaj['numesite']?>&nbsp;</div> 
                <div class = "<?=$class?> bb"><?=$mesaj['adresasite']?> &nbsp;</div>
                <div class = "<?=$class?> bb"><?=$mesaj['parola']?> &nbsp;</div>
                <div class = "<?=$class?> bb"><?=$mesaj['email']?>&nbsp; </div>

                <div class="<?=$class?> ">
                    <a href = "ag_view.php?modifica=<?=$mesaj['id']?>">
                    <img src = "imagini/modifica.gif"/></a>
                </div>

                <div class="<?=$class?> ">
                     <a href = "ag_view.php?sterge=<?=$mesaj['id']?>"
                       onclick = "return delete_confirm('Sunteti siguri ca vreti sa stergeti data !!!')">
                       
                    <img src = "imagini/sterge.gif"/></a>
                </div>

                <br class = "clear"/>

                <? $i++; }?>
            </div>





</div>
</div>
</div>
<? include "include/footer.php";  ?> 
